package com.aliyun.edu.advanced.development.thread.common.method;

/**
 * @author xiaoming
 * @version 1.0
 * @date 2019-02-23 14:35
 * 课时33 多线程常用操作方法（线程休眠）
 * 课时34 多线程常用操作方法（线程优先级）
 **/
public class Demo2Sleep {
    public static void main(String[] args) {
        System.out.println("main() 的优先级:　" +  Thread.currentThread().getPriority());
        MyThread2 mt = new MyThread2();

        Thread t1 = new Thread(mt, "休眠线程1");
        Thread t2 = new Thread(mt, "休眠线程2");

        t1.setPriority(Thread.MIN_PRIORITY);
        t2.setPriority(Thread.MAX_PRIORITY);
        t1.start();
        t2.start();
    }
}

class MyThread2 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " , i = " + i);
        }
    }
}


